#ifndef TEXTFILEDECOMPOSER_CPP
#define TEXTFILEDECOMPOSER_CPP

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <cstring>

#include "FileRAWReader/frr.01.h"
#include "Timer/timer.01.h"

using namespace std;

class TFD {
		
	public:
		
		FRR ffr;
		Timer tr;
		vector< vector<double> > v;
		
		
		void decompose(const char* filename){
			
			float g;
			uint flag(1);
			vector<double> v;
			char *mem = ffr.read(filename);
			
			tr.set();
			for (uint i=0; i<ffr.filesize; i++) {
				
				if (flag && mem[i]!=' ' && mem[i]!='\n')	{
					
					char _mem[30]; // for speed
					uint n = i-ffr.filesize; // for speed
					if (n>30) n=30; // for speed
					memcpy(_mem, &mem[i], n); // for speed
					sscanf(_mem, "%g", &g);
					
					v.push_back(g);
					flag=0;
					
				} else
					if (mem[i]==' ') flag=1;

				if (mem[i]=='\n' || i==ffr.filesize-1) { 
					this->v.push_back(v); v.erase(v.begin(), v.begin()+v.size()); 
				} 
					
					
			};
			tr.get();
		
		}
		
		void print(){
			printf("FileRead Time: %.5g\n",ffr.tr.sin);
			printf("FileDecompose Time: %.5g\n", tr.sin);
			printf("Line Number: %u\n", v.size());
		}
		
		void print_P(uint npart){
		
			for (uint j=0; j<v.size(); j++) {
				for (uint i=0; i<v[j].size(); i++)
				printf("% .3e\t",v[j][i]);
				printf("\n");
			}

		}
		
};

#endif